<template>
  <div class="span">
    <criteria-paged :model="model" v-ref:paged :pager="!row && !newArea && !areainfo" @sort="sort">
      <criteria partial='criteria' v-ref:criteria @condition-changed="$parent.selfSearch">
        <div novalidate class="form-inline auto" partial>
          <div class="form-group">
            <input type="text" class="form-control" v-model="model.f_userinfo_id"
                   condition="u.f_userinfo_id='{}'" placeholder='用户编号'
                   :size="model.f_userinfo_id ? model.f_userinfo_id.length : 4">
          </div>
          <div class="form-group">
            <input type="text" class="form-control" v-model="model.f_user_name"
                   condition="u.f_user_name like '%{}%'" placeholder='用户姓名'
                   :size="model.f_user_name ? model.f_user_name.length * 2 : 4">
          </div>
          <div class="form-group">
            <button class="btn btn-success" @click="$parent.$parent.search()">查询</button>
          </div>
        </div>
      </criteria>
      <div  partial='list'>
        <data-grid :model="model" v-ref:grid >
          <template partial='head'>
            <tr>
              <th>序号</th>
              <th>用户编号</th>
              <th>用户信息</th>
              <th>地址信息</th>
              <th>状态</th>
              <th>操作</th>
            </tr>
          </template>
          <template partial='body'>
            <td style="text-align: center;">{{$index + 1}}</td>
            <td style="text-align: center;">{{row.f_userinfo_id}}</td>
            <td style="text-align: center;">{{row.f_user_name}}&nbsp;&nbsp;{{row.f_user_phone ? row.f_user_phone : ''}}</td>
            <td style="text-align: center;">{{row.f_address_detail ? row.f_address + row.f_address_detail : row.f_address}}</td>
            <td style="text-align: center;">{{row.f_user_state}}</td>
            <td style="text-align: center;">
              <button class="btn btn-link" @click="$parent.$parent.$parent.selected(row)">收费</button>
            </td>
          </template>
        </data-grid>
      </div>
    </criteria-paged>
  </div>
</template>

<script>
  import { PagedList } from 'vue-client'
  import * as Util from '../../Util'
  export default {
    data () {
      return {
        model: new PagedList('rs/sql/getInfoForUser', 50)
      }
    },
    ready () {
      this.search()
    },
    methods: {
      search () {
        if (Util.f.parent.orgtype !== '总公司') {
          this.$refs.paged.$refs.criteria.model.f_filiale = [Util.f.f_fengongsi]
        }
        console.log('点击事件，，，，')
        this.$dispatch('research')
        // this.$refs.paged.$refs.criteria.search()
      },
      selfSearch (args) {
        // 如果隶属总公司，不加任何判断
        if (!Util.f.parent.parent.name.includes('统一资源管理') && Util.f.parent.orgtype !== '总公司') {
          args.condition = `${args.condition} and u.f_filiale = '${Util.f.f_fengongsi}'`
        }
        this.model.search(args.condition, args.model)
      },
      selected (row) {

        this.$dispatch('selected', {f_userinfo_id: row.f_userinfo_id, f_balance: row.f_balance, f_real_balance: row.f_real_balance, f_curbalance: row.f_curbalance})
      }
    }
  }
</script>
